package com.company;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

public class PCHost {

    public PCHost(int hostPort) {
        this.createDeviceHostConnection(hostPort);
    }

    //创建连接
    private void createDeviceHostConnection(int hostPort) {
        String device = null;

        Socket device_hostsocket = null;
        try {
            device_hostsocket = new Socket("localhost", hostPort);
            DataInputStream dataInputStream = new DataInputStream(device_hostsocket.getInputStream());
            DataOutputStream dataOutputStream = new DataOutputStream(device_hostsocket.getOutputStream());
            String msg = dataInputStream.readUTF();
            System.out.println(msg);
            dataOutputStream.writeUTF("猪娃: 你好，安卓");
            dataOutputStream.flush();
            dataOutputStream.close();
            dataInputStream.close();

        } catch (UnknownHostException uhe) {
            uhe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ADBExecutor adb_executor = new ADBExecutor("D:\\\\Android\\\\SDK\\\\platform-tools\\\\adb.exe");
        String deviceId = adb_executor.execAdbDevice();
        adb_executor.execAdbSingleDevicePortForward(deviceId, ADBExecutor.HOST_PORT, ADBExecutor.ANDROID_PORT);
        final PCHost host = new PCHost(ADBExecutor.HOST_PORT);
    }

}
